package com.xydzxt.www.controller.student;
import com.xydzxt.www.model.Major;
import com.xydzxt.www.model.News;
import com.xydzxt.www.model.Regist;
import com.xydzxt.www.model.User;
import com.xydzxt.www.service.MajorService;
import com.xydzxt.www.service.NewsService;
import com.xydzxt.www.service.RegistService;
import com.xydzxt.www.service.UserService;
import com.xydzxt.www.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Random;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.thymeleaf.util.DateUtils;

import javax.servlet.http.HttpSession;





//@Configuration
//public class StuHome implements WebMvcConfigurer {
//    @Override
//    public void addViewControllers(ViewControllerRegistry registry){
//        registry.addViewController("/").setViewName("index");
//        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
//    }
@Controller
public class IndexController {

        @Autowired
        NewsService newsService;
        UserService userService;
        RegistService registService;
        MajorService majorService;

    @RequestMapping({"/","/index"})
        public String index(Model model,News news){
        List<News> newsList = newsService.selectAll(news);
        model.addAttribute("newsList",newsList);
        return "student/home";
    }

    @RequestMapping("/news")
    public String news(HttpServletRequest request){

        String newsId=request.getParameter("newsId");

        if (newsId!=null && !newsId.equals("")){
            List<News> news= newsService.selectAll(newsId);
            if (news!=null){
                request.setAttribute("news",news);
            }else {
                request.setAttribute("msg","您查找的新闻id不正确或不存在！");
                return "student/msg";
            }
            return "student/applicationNotes";
        }else {
            request.setAttribute("msg","新闻id不能为空");
            return "student/msg";
        }
    }





}


//}


